package com.stonedt.spider.serviceImpl;

import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.stonedt.spider.controller.overseas.OverseasInfo;
import com.stonedt.spider.dao.BiddingDao;
import com.stonedt.spider.service.BiddingService;
import com.stonedt.spider.util.ArticlePicture;
import com.stonedt.spider.util.ElasticSearchUtil;
import com.stonedt.spider.util.UtilConfig;

@Service
public class BiddingServiceImpl implements BiddingService {
    @Autowired
    BiddingDao biddingDao;

    /**
     * 获取招标列表数据
     */
    @Override
    public JSONObject getBiddingList(Map<String, Object> map) {
    	String response = "";
		JSONObject j=new JSONObject(map);
		Map<String, Object> result = new HashMap<String, Object>();
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
    	try {
            // TODO Auto-generated method stub
            String keyword = String.valueOf(map.get("keywords"));
            String timee = String.valueOf(map.get("timee")+" 23:59:59");
            String times = String.valueOf(map.get("times")+" 00:00:00");
            String page = String.valueOf(map.get("pageNum"));
            String size = String.valueOf(map.get("size"));
            String searchType = String.valueOf(map.get("searchType"));
            String website_id = String.valueOf(map.get("website_id"));
            String searchType1 = "";
            String searchType2 = searchType;
            
            System.out.println(keyword);
            
            JSONObject end_json=new JSONObject();
            JSONArray array=new JSONArray();
            JSONArray orArr=new JSONArray();
            switch (searchType) {
			case "0":
				searchType="title";
				break;
			case "1":
				searchType="province";
				if(keyword.equals("中央")) {
	            	keyword="央企招投标";
	            }
				break;
			case "2":
				searchType="province";
				searchType1="title";
				if(keyword.equals("中央")) {
	            	keyword="央企招投标";
	            }
				break;
			}
            
            if (website_id.length()>4) {
            	String[] all_id=website_id.split(",");
            	for (int i = 0; i < all_id.length; i++) {
            		JSONObject json1=new JSONObject();
    				json1.put("field", "website_id");
    				json1.put("keyword", all_id[i]);
    	            array.add(json1);
				}
            	if(searchType2.equals("2")) {
            		if(!keyword.equals("")) {
                		JSONObject json2=new JSONObject();
                    	json2.put("field", searchType);
        	            json2.put("keyword", keyword);
        	            orArr.add(json2);
        	            JSONObject json3=new JSONObject();
                    	json3.put("field", searchType1);
        	            json3.put("keyword", keyword);
        	            orArr.add(json3);
                        end_json.put("and", orArr);
                	}
            	}else {
            		if(!keyword.equals("")) {
                		JSONObject json2=new JSONObject();
                    	json2.put("field", searchType);
        	            json2.put("keyword", keyword);
        	            orArr.add(json2);
                        end_json.put("and", orArr);
                	}
            	}
            	
                
                end_json.put("timefield", "publish_time");
                end_json.put("times", "");
                end_json.put("timee", "");
                end_json.put("index", "stonedt_biao");
                end_json.put("type", "infor");
                end_json.put("page", page);
                end_json.put("size", size);
                end_json.put("or", array);
			}else {
				JSONObject json1=new JSONObject();
				json1.put("field", "website_id");
				json1.put("keyword", website_id);
	            array.add(json1);
	            if(searchType2.equals("2")) {
            		if(!keyword.equals("")) {
                		JSONObject json2=new JSONObject();
                    	json2.put("field", searchType);
        	            json2.put("keyword", keyword);
        	            orArr.add(json2);
        	            JSONObject json3=new JSONObject();
                    	json3.put("field", searchType1);
        	            json3.put("keyword", keyword);
        	            orArr.add(json3);
                        end_json.put("or", orArr);
                	}
            	}else {
		            if(!keyword.equals("")) {
		            	JSONObject json2=new JSONObject();
		            	json2.put("field", searchType);
			            json2.put("keyword", keyword);
			            array.add(json2);
		            }
            	}
	            end_json.put("timefield", "publish_time");
	            end_json.put("times", "");
	            end_json.put("timee", "");
	            end_json.put("index", "stonedt_biao");
	            end_json.put("type", "infor");
	            end_json.put("page", page);
	            end_json.put("size", size);
	            end_json.put("and", array);
			}
            System.out.println(end_json);
            if (website_id.length()>4) {
            	 String url =  "http://dx2.stonedt.com:7120/commonsearch/superdatabankbiaolist";
                 response = OverseasInfo.sendPostRaw(end_json.toJSONString(),url,"utf-8");
            }else {
            	String url =  UtilConfig.getURL().substring(0,UtilConfig.getURL().length()-1)+ElasticSearchUtil.superdatalist;
                System.err.println(url);
                response = OverseasInfo.sendPostRaw(end_json.toJSONString(),url,"utf-8");
            }
            
        } catch (Exception e) {
			e.printStackTrace();
			result.put("list", list);
			result.put("totalData", 0);
			result.put("totalPage", 1);
			result.put("page", 0);
		}
		if (StringUtils.isNotBlank(response)) {
			JSONObject parseObject = JSON.parseObject(response);
			String totalData = parseObject.getString("count");
			String totalPage = parseObject.getString("page_count");
			String page=parseObject.getString("page");
			JSONArray jsonArray = parseObject.getJSONArray("data");
			for (int i = 0; i < jsonArray.size(); i++) {
				JSONObject jsonObject = jsonArray.getJSONObject(i);
				JSONObject jsonObject2 = jsonObject.getJSONObject("_source");
				Map<String, String> params = JSONObject.parseObject(jsonObject2.toJSONString(), new TypeReference<Map<String, String>>(){});
				list.add(params);
			}
			if (Integer.parseInt(totalData) > 10000) {
				totalPage = "500";
			}
			if (StringUtils.isBlank(totalPage)) {
				totalPage = "1";
			}else if ("0".equals(totalPage)) {
				totalPage = "1";
			}
			result.put("list", list);
			result.put("totalData", totalData);
			result.put("totalPage", totalPage);
			result.put("page", page);
		}else {
			result.put("list", list);
			result.put("totalData", 0);
			result.put("totalPage", 1);
			result.put("page", 0);
		}
		//System.err.println(new JSONObject(result));
		return new JSONObject(result);
    }
    
    @Override
    public JSONObject getSpecialList(Map<String, Object> map) {
    	String response = "";
		JSONObject j=new JSONObject(map);
		Map<String, Object> result = new HashMap<String, Object>();
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
    	try {
            // TODO Auto-generated method stub
            String keyword = String.valueOf(map.get("keywords"));
            String timee = String.valueOf(map.get("timee")+" 23:59:59");
            String times = String.valueOf(map.get("times")+" 00:00:00");
            String page = String.valueOf(map.get("pageNum"));
            String size = String.valueOf(map.get("size"));
            String searchType = String.valueOf(map.get("searchType"));
            String website_id = String.valueOf(map.get("website_id"));
            String searchType1 = "";
            String searchType2 = searchType;
            
            System.out.println(keyword);
            
            JSONObject end_json=new JSONObject();
            JSONArray array=new JSONArray();
            JSONArray orArr=new JSONArray();
            switch (searchType) {
			case "0":
				searchType="title";
				break;
			case "1":
				searchType="province";
				if(keyword.equals("中央")) {
	            	keyword="央企招投标";
	            }
				break;
			case "2":
				searchType="province";
				searchType1="title";
				if(keyword.equals("中央")) {
	            	keyword="央企招投标";
	            }
				break;
			}
            System.out.println("website_id:"+website_id);
            if (website_id.length()>4) {
            	String[] all_id=website_id.split(",");
            	for (int i = 0; i < all_id.length; i++) {
            		JSONObject json1=new JSONObject();
    				json1.put("field", "website_id");
    				json1.put("keyword", all_id[i]);
    	            array.add(json1);
				}
            	if(searchType2.equals("2")) {
            		if(!keyword.equals("")) {
                		JSONObject json2=new JSONObject();
                    	json2.put("field", searchType);
        	            json2.put("keyword", keyword);
        	            orArr.add(json2);
        	            JSONObject json3=new JSONObject();
                    	json3.put("field", searchType1);
        	            json3.put("keyword", keyword);
        	            orArr.add(json3);
                        end_json.put("and", orArr);
                	}
            	}else {
            		if(!keyword.equals("")) {
                		JSONObject json2=new JSONObject();
                    	json2.put("field", searchType);
        	            json2.put("keyword", keyword);
        	            orArr.add(json2);
                        end_json.put("and", orArr);
                	}
            	}
            	
                
                end_json.put("timefield", "publish_time");
                end_json.put("times", "");
                end_json.put("timee", "");
                end_json.put("index", "stonedt_biao");
                end_json.put("type", "infor");
                end_json.put("page", page);
                end_json.put("size", size);
                end_json.put("or", array);
			}else {
				JSONObject json1=new JSONObject();
				json1.put("field", "website_id");
				json1.put("keyword", website_id);
	            array.add(json1);
	            System.out.println("searchType2:"+searchType2);
	            if(searchType2.equals("2")) {
	            	System.out.println("aaaaaaa");
	            	System.out.println("keyword:"+keyword);
            		if(!keyword.equals("")) {
            			System.out.println("bbbbbbbbbbbbb");
                		JSONObject json2=new JSONObject();
                    	json2.put("field", searchType);
        	            json2.put("keyword", keyword);
        	            orArr.add(json2);
        	            JSONObject json3=new JSONObject();
                    	json3.put("field", searchType1);
        	            json3.put("keyword", keyword);
        	            orArr.add(json3);
                        end_json.put("or", orArr);
                	}
            	}else {
		            if(!keyword.equals("")) {
		            	JSONObject json2=new JSONObject();
		            	json2.put("field", searchType);
			            json2.put("keyword", keyword);
			            array.add(json2);
		            }
            	}
	            end_json.put("timefield", "publish_time");
	            end_json.put("times", "");
	            end_json.put("timee", "");
	            end_json.put("index", "stonedt_biao");
	            end_json.put("type", "infor");
	            end_json.put("page", page);
	            end_json.put("size", size);
	            end_json.put("and", array);
			}
            System.out.println("end_json:"+end_json);
            if (website_id.length()>4) {
            	 String url =  "http://dx2.stonedt.com:7120/commonsearch/superdatabankbiaolist";
                 response = OverseasInfo.sendPostRaw(end_json.toJSONString(),url,"utf-8");
            }else {
            	String url =  UtilConfig.getURL().substring(0,UtilConfig.getURL().length()-1)+ElasticSearchUtil.superdatalist;
                System.err.println(url);
                response = OverseasInfo.sendPostRaw(end_json.toJSONString(),url,"utf-8");
            }
            
        } catch (Exception e) {
			e.printStackTrace();
			result.put("list", list);
			result.put("totalData", 0);
			result.put("totalPage", 1);
			result.put("page", 0);
		}
		if (StringUtils.isNotBlank(response)) {
			JSONObject parseObject = JSON.parseObject(response);
			String totalData = parseObject.getString("count");
			String totalPage = parseObject.getString("page_count");
			String page=parseObject.getString("page");
			JSONArray jsonArray = parseObject.getJSONArray("data");
			for (int i = 0; i < jsonArray.size(); i++) {
				JSONObject jsonObject = jsonArray.getJSONObject(i);
				JSONObject jsonObject2 = jsonObject.getJSONObject("_source");
				Map<String, String> params = JSONObject.parseObject(jsonObject2.toJSONString(), new TypeReference<Map<String, String>>(){});
				list.add(params);
			}
			if (Integer.parseInt(totalData) > 10000) {
				totalPage = "500";
			}
			if (StringUtils.isBlank(totalPage)) {
				totalPage = "1";
			}else if ("0".equals(totalPage)) {
				totalPage = "1";
			}
			result.put("list", list);
			result.put("totalData", totalData);
			result.put("totalPage", totalPage);
			result.put("page", page);
		}else {
			result.put("list", list);
			result.put("totalData", 0);
			result.put("totalPage", 1);
			result.put("page", 0);
		}
		//System.err.println(new JSONObject(result));
		return new JSONObject(result);
    }
    
    @Override
    public JSONObject getElectricRailwayList(Map<String, Object> map) {
    	String response = "";
		JSONObject j=new JSONObject(map);
		Map<String, Object> result = new HashMap<String, Object>();
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
    	try {
            // TODO Auto-generated method stub
            String keyword = String.valueOf(map.get("keywords"));
            String timee = String.valueOf(map.get("timee")+" 23:59:59");
            String times = String.valueOf(map.get("times")+" 00:00:00");
            String page = String.valueOf(map.get("pageNum"));
            String size = String.valueOf(map.get("size"));
            String searchType = String.valueOf(map.get("searchType"));
            String website_id = String.valueOf(map.get("website_id"));
            String searchType1 = "";
            String searchType2 = searchType;
            
            System.out.println(keyword);
            
            JSONObject end_json=new JSONObject();
            JSONArray array=new JSONArray();
            JSONArray orArr=new JSONArray();
            switch (searchType) {
			case "0":
				searchType="title";
				break;
			case "1":
				searchType="province";
				if(keyword.equals("中央")) {
	            	keyword="央企招投标";
	            }
				break;
			case "2":
				searchType="province";
				searchType1="title";
				if(keyword.equals("中央")) {
	            	keyword="央企招投标";
	            }
				break;
			}
            System.out.println("website_id:"+website_id);
            if (website_id.length()>4) {
            	String[] all_id=website_id.split(",");
            	for (int i = 0; i < all_id.length; i++) {
            		JSONObject json1=new JSONObject();
    				json1.put("field", "website_id");
    				json1.put("keyword", all_id[i]);
    	            array.add(json1);
				}
            	if(searchType2.equals("2")) {
            		if(!keyword.equals("")) {
                		JSONObject json2=new JSONObject();
                    	json2.put("field", searchType);
        	            json2.put("keyword", keyword);
        	            orArr.add(json2);
        	            JSONObject json3=new JSONObject();
                    	json3.put("field", searchType1);
        	            json3.put("keyword", keyword);
        	            orArr.add(json3);
                        end_json.put("and", orArr);
                	}
            	}else {
            		if(!keyword.equals("")) {
                		JSONObject json2=new JSONObject();
                    	json2.put("field", searchType);
        	            json2.put("keyword", keyword);
        	            orArr.add(json2);
                        end_json.put("and", orArr);
                	}
            	}
            	
                
                end_json.put("timefield", "publish_time");
                end_json.put("times", "");
                end_json.put("timee", "");
                end_json.put("index", "stonedt_biao");
                end_json.put("type", "infor");
                end_json.put("page", page);
                end_json.put("size", size);
                end_json.put("or", array);
			}else {
				JSONObject json1=new JSONObject();
				json1.put("field", "website_id");
				json1.put("keyword", website_id);
	            array.add(json1);
	            System.out.println("searchType2:"+searchType2);
	            if(searchType2.equals("2")) {
	            	System.out.println("aaaaaaaaaaaaaaa");
	            	System.out.println("keyword:"+keyword);
            		if(!keyword.equals("")) {
            			System.out.println("bbbbbbbbbb");
                		JSONObject json2=new JSONObject();
                    	json2.put("field", searchType);
        	            json2.put("keyword", keyword);
        	            orArr.add(json2);
        	            JSONObject json3=new JSONObject();
                    	json3.put("field", searchType1);
        	            json3.put("keyword", keyword);
        	            orArr.add(json3);
                        end_json.put("or", orArr);
                	}
            	}else {
		            if(!keyword.equals("")) {
		            	JSONObject json2=new JSONObject();
		            	json2.put("field", searchType);
			            json2.put("keyword", keyword);
			            array.add(json2);
		            }
            	}
	            end_json.put("timefield", "publish_time");
	            end_json.put("times", "");
	            end_json.put("timee", "");
	            end_json.put("index", "stonedt_biao");
	            end_json.put("type", "infor");
	            end_json.put("page", page);
	            end_json.put("size", size);
	            end_json.put("and", array);
			}
            System.out.println("end_json:"+end_json);
            if (website_id.length()>4) {
            	 String url =  "http://dx2.stonedt.com:7120/commonsearch/superdatabankbiaolist";
                 response = OverseasInfo.sendPostRaw(end_json.toJSONString(),url,"utf-8");
            }else {
            	String url =  UtilConfig.getURL().substring(0,UtilConfig.getURL().length()-1)+ElasticSearchUtil.superdatalist;
                System.err.println(url);
                response = OverseasInfo.sendPostRaw(end_json.toJSONString(),url,"utf-8");
            }
            
        } catch (Exception e) {
			e.printStackTrace();
			result.put("list", list);
			result.put("totalData", 0);
			result.put("totalPage", 1);
			result.put("page", 0);
		}
		if (StringUtils.isNotBlank(response)) {
			JSONObject parseObject = JSON.parseObject(response);
			String totalData = parseObject.getString("count");
			String totalPage = parseObject.getString("page_count");
			String page=parseObject.getString("page");
			JSONArray jsonArray = parseObject.getJSONArray("data");
			for (int i = 0; i < jsonArray.size(); i++) {
				JSONObject jsonObject = jsonArray.getJSONObject(i);
				JSONObject jsonObject2 = jsonObject.getJSONObject("_source");
				Map<String, String> params = JSONObject.parseObject(jsonObject2.toJSONString(), new TypeReference<Map<String, String>>(){});
				list.add(params);
			}
			if (Integer.parseInt(totalData) > 10000) {
				totalPage = "500";
			}
			if (StringUtils.isBlank(totalPage)) {
				totalPage = "1";
			}else if ("0".equals(totalPage)) {
				totalPage = "1";
			}
			result.put("list", list);
			result.put("totalData", totalData);
			result.put("totalPage", totalPage);
			result.put("page", page);
		}else {
			result.put("list", list);
			result.put("totalData", 0);
			result.put("totalPage", 1);
			result.put("page", 0);
		}
		//System.err.println(new JSONObject(result));
		return new JSONObject(result);
    }
    
    @Override
    public JSONObject getSynthesizeList(Map<String, Object> map) {
    	String response = "";
		JSONObject j=new JSONObject(map);
		Map<String, Object> result = new HashMap<String, Object>();
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
    	try {
            // TODO Auto-generated method stub
            String keyword = String.valueOf(map.get("keywords"));
            String timee = String.valueOf(map.get("timee")+" 23:59:59");
            String times = String.valueOf(map.get("times")+" 00:00:00");
            String page = String.valueOf(map.get("pageNum"));
            String size = String.valueOf(map.get("size"));
            String searchType = String.valueOf(map.get("searchType"));
            String website_id = String.valueOf(map.get("website_id"));
            String searchType1 = "";
            String searchType2 = searchType;
            
            System.out.println(keyword);
            
            JSONObject end_json=new JSONObject();
            JSONArray array=new JSONArray();
            JSONArray orArr=new JSONArray();
            switch (searchType) {
			case "0":
				searchType="title";
				break;
			case "1":
				searchType="province";
				if(keyword.equals("中央")) {
	            	keyword="央企招投标";
	            }
				break;
			case "2":
				searchType="province";
				searchType1="title";
				if(keyword.equals("中央")) {
	            	keyword="央企招投标";
	            }
				break;
			}
            System.out.println("website_id:"+website_id);
            if (website_id.length()>4) {
            	String[] all_id=website_id.split(",");
            	for (int i = 0; i < all_id.length; i++) {
            		JSONObject json1=new JSONObject();
    				json1.put("field", "website_id");
    				json1.put("keyword", all_id[i]);
    	            array.add(json1);
				}
            	if(searchType2.equals("2")) {
            		if(!keyword.equals("")) {
                		JSONObject json2=new JSONObject();
                    	json2.put("field", searchType);
        	            json2.put("keyword", keyword);
        	            orArr.add(json2);
        	            JSONObject json3=new JSONObject();
                    	json3.put("field", searchType1);
        	            json3.put("keyword", keyword);
        	            orArr.add(json3);
                        end_json.put("and", orArr);
                	}
            	}else {
            		if(!keyword.equals("")) {
                		JSONObject json2=new JSONObject();
                    	json2.put("field", searchType);
        	            json2.put("keyword", keyword);
        	            orArr.add(json2);
                        end_json.put("and", orArr);
                	}
            	}
            	
                
                end_json.put("timefield", "publish_time");
                end_json.put("times", "");
                end_json.put("timee", "");
                end_json.put("index", "stonedt_biao");
                end_json.put("type", "infor");
                end_json.put("page", page);
                end_json.put("size", size);
                end_json.put("or", array);
			}else {
				JSONObject json1=new JSONObject();
				json1.put("field", "website_id");
				json1.put("keyword", website_id);
	            array.add(json1);
	            System.out.println("searchType2:"+searchType2);
	            if(searchType2.equals("2")) {
	            	System.out.println("aaaaaaaaaaaaaaa");
	            	System.out.println("keyword:"+keyword);
            		if(!keyword.equals("")) {
            			System.out.println("bbbbbbbbbb");
                		JSONObject json2=new JSONObject();
                    	json2.put("field", searchType);
        	            json2.put("keyword", keyword);
        	            orArr.add(json2);
        	            JSONObject json3=new JSONObject();
                    	json3.put("field", searchType1);
        	            json3.put("keyword", keyword);
        	            orArr.add(json3);
                        end_json.put("or", orArr);
                	}
            	}else {
		            if(!keyword.equals("")) {
		            	JSONObject json2=new JSONObject();
		            	json2.put("field", searchType);
			            json2.put("keyword", keyword);
			            array.add(json2);
		            }
            	}
	            end_json.put("timefield", "publish_time");
	            end_json.put("times", "");
	            end_json.put("timee", "");
	            end_json.put("index", "stonedt_biao");
	            end_json.put("type", "infor");
	            end_json.put("page", page);
	            end_json.put("size", size);
	            end_json.put("and", array);
			}
            System.out.println("end_json:"+end_json);
            if (website_id.length()>4) {
            	 String url =  "http://dx2.stonedt.com:7120/commonsearch/superdatabankbiaolist";
                 response = OverseasInfo.sendPostRaw(end_json.toJSONString(),url,"utf-8");
            }else {
            	String url =  UtilConfig.getURL().substring(0,UtilConfig.getURL().length()-1)+ElasticSearchUtil.superdatalist;
                System.err.println(url);
                response = OverseasInfo.sendPostRaw(end_json.toJSONString(),url,"utf-8");
            }
            
        } catch (Exception e) {
			e.printStackTrace();
			result.put("list", list);
			result.put("totalData", 0);
			result.put("totalPage", 1);
			result.put("page", 0);
		}
		if (StringUtils.isNotBlank(response)) {
			JSONObject parseObject = JSON.parseObject(response);
			String totalData = parseObject.getString("count");
			String totalPage = parseObject.getString("page_count");
			String page=parseObject.getString("page");
			JSONArray jsonArray = parseObject.getJSONArray("data");
			for (int i = 0; i < jsonArray.size(); i++) {
				JSONObject jsonObject = jsonArray.getJSONObject(i);
				JSONObject jsonObject2 = jsonObject.getJSONObject("_source");
				Map<String, String> params = JSONObject.parseObject(jsonObject2.toJSONString(), new TypeReference<Map<String, String>>(){});
				list.add(params);
			}
			if (Integer.parseInt(totalData) > 10000) {
				totalPage = "500";
			}
			if (StringUtils.isBlank(totalPage)) {
				totalPage = "1";
			}else if ("0".equals(totalPage)) {
				totalPage = "1";
			}
			result.put("list", list);
			result.put("totalData", totalData);
			result.put("totalPage", totalPage);
			result.put("page", page);
		}else {
			result.put("list", list);
			result.put("totalData", 0);
			result.put("totalPage", 1);
			result.put("page", 0);
		}
		//System.err.println(new JSONObject(result));
		return new JSONObject(result);
    }

    /**
     * 获取信息类型
     */
    @Override
	public JSONArray getInformationtype() {
        JSONArray returnArray = new JSONArray();
        /*
         * List<Map<String,Object>> informationtypes = biddingDao.getInformationtype();
		 * returnArray = JSONArray.parseArray(JSON.toJSONString(informationtypes));
		 * System.out.println(returnArray.toString());
		 */
        try {
            String params = "";
            String api = ElasticSearchUtil.invitateinformationtype;
            String url = UtilConfig.getURL() + api;
            System.out.println(url + params);
            String responseData = ElasticSearchUtil.sendPost1(url, params);
            JSONObject responseJson = JSON.parseObject(responseData);
            JSONObject aggregationsJson = responseJson.getJSONObject("aggregations");
            JSONObject group_by_tagsJson = aggregationsJson.getJSONObject("group_by_tags");
            returnArray = group_by_tagsJson.getJSONArray("buckets");

        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }

        return returnArray;
    }

    /**
     * 获取省份信息
     *
     * @return
     */
    @Override
    public JSONObject getProvinceAsyn(Map<String, String> map) {
        JSONObject provinceData = new JSONObject();
        try {
            String api = ElasticSearchUtil.invitateprovince;
            String url = UtilConfig.getURL() + api;
            String province = "";
            String city ="";
            String businessType = "";
            String informationtype = "";
            String params = "?&province=" + URLEncoder.encode(province, "utf-8") + "&city=" + URLEncoder.encode(city, "utf-8")
                    + "&businessType=" + URLEncoder.encode(businessType, "utf-8") + "&informationtype=" + URLEncoder.encode(informationtype, "utf-8");
            String esResponse = ElasticSearchUtil.sendPost1(url, params);
            if (esResponse != null && !"".equals(esResponse)) {
                JSONObject esResponseJson = JSON.parseObject(esResponse);
                JSONObject aggregationsJson = esResponseJson.getJSONObject("aggregations");
                JSONObject group_by_tagsJson = aggregationsJson.getJSONObject("group_by_tags");
                JSONArray bucketArray = group_by_tagsJson.getJSONArray("buckets");
                provinceData.put("code", "200");
                provinceData.put("msg", "获取省份信息成功！");
                provinceData.put("data", bucketArray);
            }
        } catch (Exception e) {
            e.printStackTrace();
            JSONArray bucketArray = new JSONArray();
            provinceData.put("code", "500");
            provinceData.put("msg", "获取省份信息异常！");
            provinceData.put("data", bucketArray);
        }
        return provinceData;
    }

    @Override
    public JSONObject getCityAsyn(Map<String, String> map) {
        JSONObject cityData = new JSONObject();
        try {
            String province = map.get("province");
            String city ="";
            String businessType = "";
            String informationtype = "";
            String api = ElasticSearchUtil.invitatecity;
            String url = UtilConfig.getURL() + api;
            String params = "?&province=" + URLEncoder.encode(province, "utf-8") + "&city=" + URLEncoder.encode(city, "utf-8")
                    + "&businessType=" + URLEncoder.encode(businessType, "utf-8") + "&informationtype=" + URLEncoder.encode(informationtype, "utf-8");
            String esResponse = ElasticSearchUtil.sendPost1(url, params);
            if (esResponse != null && !"".equals(esResponse)) {
                JSONObject esResponseJson = JSON.parseObject(esResponse);
                JSONObject aggregationsJson = esResponseJson.getJSONObject("aggregations");
                JSONObject group_by_tagsJson = aggregationsJson.getJSONObject("group_by_tags");
                JSONArray bucketArray = group_by_tagsJson.getJSONArray("buckets");
                cityData.put("code", "200");
                cityData.put("msg", "获取城市信息成功！");
                cityData.put("data", bucketArray);
            }
        } catch (Exception e) {
            e.printStackTrace();
            JSONArray bucketArray = new JSONArray();
            cityData.put("code", "500");
            cityData.put("msg", "获取城市信息异常！");
            cityData.put("data", bucketArray);
        }
        return cityData;
    }

    @Override
    public JSONObject getIndustryAsyn(Map<String, String> map) {
        JSONObject industryData = new JSONObject();
        try {
            String api = ElasticSearchUtil.invitateindustry;
            String url = UtilConfig.getURL() + api;
            String province = "";
            String city ="";
            String businessType = "";
            String informationtype = "";
            String params = "?&province=" + URLEncoder.encode(province, "utf-8") + "&city=" + URLEncoder.encode(city, "utf-8")
                    + "&businessType=" + URLEncoder.encode(businessType, "utf-8") + "&informationtype=" + URLEncoder.encode(informationtype, "utf-8");
            String esResponse = ElasticSearchUtil.sendPost1(url, params);
            if (esResponse != null && !"".equals(esResponse)) {
                JSONObject esResponseJson = JSON.parseObject(esResponse);
                JSONObject aggregationsJson = esResponseJson.getJSONObject("aggregations");
                JSONObject group_by_tagsJson = aggregationsJson.getJSONObject("group_by_tags");
                JSONArray bucketArray = group_by_tagsJson.getJSONArray("buckets");
                industryData.put("code", "200");
                industryData.put("msg", "获取行业信息成功！");
                industryData.put("data", bucketArray);
            }
        } catch (Exception e) {
            e.printStackTrace();
            JSONArray bucketArray = new JSONArray();
            industryData.put("code", "500");
            industryData.put("msg", "获取行业信息异常！");
            industryData.put("data", bucketArray);
        }
        return industryData;
    }

    @Override
    public JSONObject getbusinessTypeAsyn(Map<String, String> map) {
        JSONObject businessTypeData = new JSONObject();
        try {
            String api = ElasticSearchUtil.invitatebusinessType;
            String url = UtilConfig.getURL() + api;
            String province = "";
            String city = "";
            String businessType = "";
            String informationtype = "";
            String params = "?&province=" + URLEncoder.encode(province, "utf-8") + "&city=" + URLEncoder.encode(city, "utf-8")
                    + "&businessType=" + URLEncoder.encode(businessType, "utf-8") + "&informationtype=" + URLEncoder.encode(informationtype, "utf-8");
            String esResponse = ElasticSearchUtil.sendPost1(url, params);
            if (esResponse != null && !"".equals(esResponse)) {
                JSONObject esResponseJson = JSON.parseObject(esResponse);
                JSONObject aggregationsJson = esResponseJson.getJSONObject("aggregations");
                JSONObject group_by_tagsJson = aggregationsJson.getJSONObject("group_by_tags");
                JSONArray bucketArray = group_by_tagsJson.getJSONArray("buckets");
                businessTypeData.put("code", "200");
                businessTypeData.put("msg", "获取业务类型信息成功！");
                businessTypeData.put("data", bucketArray);
            }
        } catch (Exception e) {
            e.printStackTrace();
            JSONArray bucketArray = new JSONArray();
            businessTypeData.put("code", "500");
            businessTypeData.put("msg", "获取业务类型信息异常！");
            businessTypeData.put("data", bucketArray);
        }
        return businessTypeData;
    }

    /**
     * 获取详细页面数据
     */
    @Override
    public JSONObject getBiddingDetail(Map<String, Object> map) {
        // TODO Auto-generated method stub
        JSONObject returnObj = new JSONObject();
        try {
            String article_public_id = String.valueOf(map.get("article_public_id"));
            String api = ElasticSearchUtil.invitatedetail;
            String url = UtilConfig.getURL() + api;
            String params = "?&article_public_id=" + article_public_id;
            String responseData = ElasticSearchUtil.sendPost1(url, params);
            returnObj = JSON.parseObject(responseData);
            /*//格式化content_html
            String content_html=ArticlePicture.getFormatting(returnObj.getString("content_html"));
            returnObj.remove("returnObj");
            returnObj.put("content_html", content_html);*/
        } catch (Exception e) {
            // TODO: handle exception
        }
        return returnObj;
    }
    
    public static String getJsonHtml(String url,String Referer, JSONObject jsonObject) throws Exception {
		String result ="";
		HttpClient httpClient = new DefaultHttpClient();
		HttpPost post = new HttpPost(url);
		StringEntity postingString = new StringEntity(jsonObject.toString());// json传递
		post.setEntity(postingString);
		post.setHeader("Referer", Referer);
		post.setHeader("Content-type", "application/json");
		HttpResponse response = httpClient.execute(post);
		String content = EntityUtils.toString(response.getEntity());
		// Log.i("test",content);
		result = content;
		return result;
	}

}
